# Contributor: Mika Havela <mika.havela@gmail.com>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
_luaver=5.2
pkgname=prosody
pkgver=0.11.5
pkgrel=1
pkgdesc="Lua based Jabber/XMPP server"
url="http://prosody.im/"
arch="all"
license="MIT"
depends="lua$_luaver-socket lua$_luaver-expat lua$_luaver-filesystem
	lua$_luaver-sec lua$_luaver lua$_luaver-busted"
makedepends="linux-headers lua$_luaver-dev libidn-dev openssl-dev"
checkdepends="lua-busted"
install="prosody.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
pkgusers="prosody"
pkggroups="prosody"
source="https://prosody.im/downloads/source/prosody-$pkgver.tar.gz
	prosody.cfg.lua.patch
	$pkgname.initd
	"

build() {
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc/prosody \
		--ostype=linux \
		--with-lua-lib=/usr/lib \
		--with-lua-include=/usr/include \
		--lua-version=$_luaver \
		--no-example-certs \
		--runwith=lua$_luaver
	# Don't generate certs
	rm -f "$builddir"/certs/Makefile

	make
}

check() {
	/usr/bin/lua$_luaver /usr/bin/busted --lua=/usr/bin/lua$_luaver
}

package() {
	make DESTDIR="$pkgdir" install

	install -d -o prosody -g prosody "$pkgdir/var/log/prosody"
	install -d -o prosody -g prosody "$pkgdir/var/run/prosody"
	install -d -m750 -o prosody -g prosody "$pkgdir/var/lib/prosody"

	install -D -m755 "$srcdir"/"$pkgname".initd "$pkgdir"/etc/init.d/"$pkgname"
}

sha512sums="43a9facee8d61b69e277e7e8a9091fbfa60be71d6141195dff991f6020c8afadacce26f356b869cb2d7edd9be285e9ce1bcd822f9628cc845d91757e818a0dff  prosody-0.11.5.tar.gz
39c06eddea79c66f8a2e3b1ba1a7aa1bcf2f3f6b9315d7da55ab73e222188fe5cd982c4f435d702b62538717a5ad6a10a06252baf0e5ea31da475782257efd9f  prosody.cfg.lua.patch
24360603dbd5d2a92758e6c4b4aab4f02cbd05373580cba2df76df98b6045891e8108e8c2d16af9508e93968ed5880db952e7a21b2742ebeec6f14b167968c2c  prosody.initd"
